#include <myheader.h>
#define MMAP_SIZE 9
/*Usage: 实现文件映射参数：path (需要映射的文件路径)  */
int main(int argc, char *argv[])
{
    ARGC_CHECK(argc,2);
    int fd = open(argv[1],O_RDWR);
    ERROR_CHECK(fd,-1,"open");
    //定义指针来指向即将mmap的返回指针
    //进行文件映射映射区域可读可写，并且修改可以影响源文件
    char*  mmp_ptr = (char*)mmap(NULL,MMAP_SIZE,PROT_READ | PROT_WRITE, MAP_SHARED,fd,0);

    ERROR_CHECK(mmp_ptr,MAP_FAILED,"mmp");
    //打印
    char* temp = mmp_ptr;
    for(int i = 0; i < MMAP_SIZE; i++){
        printf("%c",mmp_ptr[i]);
    }
    printf("\n");
    //修改
    mmp_ptr[3] = '3';
    
    for(int i = 0; i < MMAP_SIZE; i++){
        printf("%c",mmp_ptr[i]);
    }
    printf("\n");
    int ummp_ret =  munmap(mmp_ptr,MMAP_SIZE);
    ERROR_CHECK(ummp_ret,-1,"ummp");
    int close_ret = close(fd);
    ERROR_CHECK(close_ret,-1,"close");
    return 0;
}

